package com.ccjk.beusoft.thirdlib.plugin1.hook.handler;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.text.TextUtils;
import android.util.Log;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * Created by CCJK on 2017/12/20.
 */

public class PackageManagerHook implements InvocationHandler {
    private final Context context;
    Object originIPackageManager;

    public PackageManagerHook(Context context, Object originIPackageManager) {
        this.context = context;
        this.originIPackageManager = originIPackageManager;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Log.e("PackageManagerHook", Thread.currentThread().getName()+" : "+method.getName());
//        if (TextUtils.equals(method.getName(), "getPackageInfo") && !PluginManager1.get().isHost(args[0].toString())) {
        if (TextUtils.equals(method.getName(), "getPackageInfo")) {
//            return PluginManager1.get().getPluginPackageInfo(args[0].toString());

            return new PackageInfo();
        }
        return method.invoke(originIPackageManager, args);
    }
}
